//
//  M1MemberHeaderView.m
//  NewMarryU
//
//  Created by Cedar on 2018/7/20.
//  Copyright © 2018年 Cedar. All rights reserved.
//

#import "M1MemberHeaderView.h"
#import "M1MemberPrerogativeCell.h"

@interface M1MemberHeaderView ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *m1_tableView;

@property (nonatomic ,copy)   NSArray *m1_array;
@end

@implementation M1MemberHeaderView

- (void)layoutSubviews{
    [super layoutSubviews];
    
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        UIImageView *bgImage = [[UIImageView alloc] initWithFrame:frame];
        bgImage.image = LOAD_LOCAL_IMG(@"personal_vip_bgView");
        [self addSubview:bgImage];

        _m1_array = @[@[@{@"title":@"优先参与",@"image":@"vip_cy"},
                        @{@"title":@"恋爱贴身",@"image":@"vip_24"},
                        @{@"title":@"置顶一天",@"image":@"vip_zd"},],
                      @[@{@"title":@"会员标识",@"image":@"vip_bs"},
                        @{@"title":@"交换微信",@"image":@"vip_wx"},
                        @{@"title":@"优先展示",@"image":@"vip_zs"},
                        @{@"title":@"高级搜索",@"image":@"vip_ss"},
                        @{@"title":@"优先审核",@"image":@"vip_sh"},
                        @{@"title":@"无限畅聊",@"image":@"vip_lt"},
                        @{@"title":@"在线状态",@"image":@"vip_zx"},
                        @{@"title":@"优先参与",@"image":@"vip_cy"},
                        @{@"title":@"查看全部",@"image":@"vip_qb"},
                        @{@"title":@"优先推荐",@"image":@"vip_tj"},]];
        
        [self m1_createUI];
        
    }
    return self;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat heightForRow = 0;
    
    if (indexPath.section == 0) {
        heightForRow = 65;
    }else{
        heightForRow = 65 * 3;
    }
    
    return heightForRow;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *viewForHeader = nil;
    
    if (section == 0) {
        viewForHeader = [self m1_viewForHeader:@"年费会员独享"];
    }else{
        viewForHeader = [self m1_viewForHeader:@"会员权利"];
    }
    
    return viewForHeader;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    CGFloat heightForHeader = 0.01;
    
    if (section == 0) {
        heightForHeader = 60;
    }else{
        heightForHeader = 60;
    }
    
    return heightForHeader;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *viewForFooter = nil;
    
    return viewForFooter;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    CGFloat heightForFooter = 0.01;
    
    return heightForFooter;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    M1MemberPrerogativeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"M1MemberPrerogativeCellIdentifierTwo"];
    
    cell.backgroundColor = [UIColor clearColor];

    cell.m1_dataArray = _m1_array[indexPath.section];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (void) m1_createUI{
    self.m1_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame)) style:UITableViewStyleGrouped];
    self.m1_tableView.backgroundColor = [UIColor clearColor];
    self.m1_tableView.dataSource = self;
    self.m1_tableView.delegate = self;
    self.m1_tableView.showsVerticalScrollIndicator = NO;
    self.m1_tableView.showsHorizontalScrollIndicator = NO;
    self.m1_tableView.userInteractionEnabled = NO;
    self.m1_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self addSubview:self.m1_tableView];
    
    
    if (@available(iOS 11.0, *))
    {
        self.m1_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }

    [self.m1_tableView registerNib:[UINib nibWithNibName:@"M1MemberPrerogativeCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"M1MemberPrerogativeCellIdentifierTwo"];

}


- (UIView *)m1_viewForHeader:(NSString *)text{
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH - 40, 60)];
    bgView.backgroundColor = [UIColor clearColor];
    
    UILabel *title = [[UILabel alloc] init];
    title.text = text;
    title.textColor = m1_color(0xFFFFFF);
    title.font = [UIFont fontWithName:@"FZLTTHK--GBK1-0" size:17];
    [bgView addSubview:title];
    
    [title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(bgView.mas_centerX);
        make.centerY.equalTo(bgView.mas_centerY);
    }];
    
    UIView *line1 = [[UIView alloc] init];
    line1.backgroundColor = m1_color(0xFFFFFF);
    [bgView addSubview:line1];
    
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(title.mas_centerY);
        make.right.equalTo(title.mas_left).offset(-19);
        make.size.mas_equalTo(CGSizeMake(34, 2));
    }];
    
    UIView *line2 = [[UIView alloc] init];
    line2.backgroundColor = m1_color(0xFFFFFF);
    [bgView addSubview:line2];
    
    [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(title.mas_centerY);
        make.left.equalTo(title.mas_right).offset(19);
        make.size.mas_equalTo(CGSizeMake(34, 2));
    }];
    
    return bgView;
}

@end
